var t = getApp();

Component({
    properties: {
        nowTime: {
            type: Number
        },
        overTime: {
            type: Number
        },
        getTime: {
            type: Number
        }
    },
    data: {
        time: null,
        timer: null,
        content: "",
        flag: !0,
        text: [ "天", "时", "分", "秒" ],
        newtime: null,
        timers: null,
        newcontent: "",
        newflag: !0
    },
    ready: function() {
        t._isTextEmpty(this.properties.getTime) ? (this.setData({
            newflag: !1
        }), this.time()) : (this.timer(), this.setData({
            flag: !1
        }));
    },
    detached: function() {
        clearInterval(this.data.timer);
    },
    methods: {
        time: function() {
            var t = this;
            this.data.timer = setInterval(function() {
                t.countDown();
                var e = t.data.time;
                e -= 1, t.setData({
                    time: e
                });
            }, 1e3);
        },
        countDown: function() {
            var t, e = this, a = this.data, n = a.overTime, i = a.nowTime, r = a.timer;
            if (n < i) return clearInterval(r), this.setData({
                flag: !1
            }), !0;
            if (!this.data.time) {
                var o = n - i;
                this.setData({
                    time: o
                });
            }
            if (0 === (t = this.data.time)) return clearInterval(r), this.setData({
                flag: !1
            }), !0;
            var s = "";
            [ Math.floor(t / 86400), Math.floor(t % 86400 / 3600), Math.floor(t % 86400 % 3600 / 60), Math.floor(t % 86400 % 3600 % 60) ].map(function(t, e) {
                return t < 10 ? "0".concat(t) : t;
            }).forEach(function(t, a) {
                s += "".concat(t).concat(e.data.text[a]);
            }), this.setData({
                content: s
            });
        },
        timer: function() {
            var t = this;
            this.setData({
                timers: setInterval(function() {
                    t.countStartDown();
                    var e = t.data.newtime;
                    e -= 1, t.setData({
                        newtime: e
                    });
                }, 1e3)
            });
        },
        countStartDown: function() {
            var t, e = this, a = this.data, n = a.getTime, i = a.nowTime, r = a.timers;
            if (n < i) return clearInterval(r), this.setData({
                newflag: !1
            }), !0;
            if (!this.data.newtime) {
                var o = n - i;
                this.setData({
                    newtime: o
                });
            }
            if (0 === (t = this.data.newtime)) return clearInterval(r), this.setData({
                newflag: !1
            }), !0;
            var s = "";
            [ Math.floor(t / 86400), Math.floor(t % 86400 / 3600), Math.floor(t % 86400 % 3600 / 60), Math.floor(t % 86400 % 3600 % 60) ].map(function(t, e) {
                return t < 10 ? "0".concat(t) : t;
            }).forEach(function(t, a) {
                s += "".concat(t).concat(e.data.text[a]);
            }), this.setData({
                newcontent: s
            });
        }
    }
});